<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
</head>
<body>

<div th:fragment="page" th:object="${page}" th:if="${page.totalPages gt 0}">
 
	<ul class="pagination" th:if="${page.totalPages le 7}" >
	<!-- 处理页数小于等于7 的情况 -->
	 	<!-- 总记录数 -->
 		<li class="tbpage-total-elements disabled">共[[${page.totalElements}]]条</li>
 		
 		<!-- 页面大小 -->
		<select class="custom-select tbpage-size" th:attr="pageIndex=${page.number}">
			<option th:each="i : ${#arrays.toIntegerArray({5,10,40,100})}" th:value="${i}" th:selected="${i eq page.size}"
				 th:text="${i}"></option>
		</select>
		
		<!-- 上一页 -->
		<li class="page-item" th:classappend="*{first} ? 'disabled' : ''">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} - 1" aria-label="Previous">
				<span aria-hidden="true">«</span>
			</a>
		</li>
		
		<!-- 迭代生成页码 -->
		<li class="page-item" th:each="i : ${#numbers.sequence(1, page.totalPages)}" 
			th:classappend="${(page.number + 1) eq i} ? 'active' : ''" >
			<a class="page-link tbpage-item" th:attr="pageIndex=${i} - 1" href="javascript:void(0);">
                 <span th:text="${i}"></span>
            </a>
		</li>
		
		<!-- 下一页 -->
		<li class="page-item" th:classappend="*{last} ? 'disabled' : ''">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} + 1" aria-label="Next">
				<span aria-hidden="true">»</span>
			</a>
		</li>
	</ul>
		
	<ul class="pagination" th:if="${page.totalPages gt 7}" >
	<!-- 处理页数大于7 的情况 -->	
	 	<!-- 总记录数 -->
 		<li class="tbpage-total-elements disabled">共[[${page.totalElements}]]条</li>
 		
 		<!-- 页面大小 -->
		<select class="custom-select tbpage-size" th:attr="pageIndex=${page.number}">
			<option th:each="i : ${#arrays.toIntegerArray({5,10,40,100})}" th:value="${i}" 
				 th:selected="${i eq page.size}" th:text="${i}"></option>
		</select>
		
	 	<!-- 上一页 -->
		<li class="page-item" th:classappend="*{first} ? 'disabled' : ''">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} - 1" aria-label="Previous">
				<span aria-hidden="true">«</span>
			</a>
		</li>
		
 		<!-- 首页 -->
		<li class="page-item" th:classappend="${(page.number + 1) eq 1} ? 'active' : ''" >
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=0">1</a>
		</li>
		 
		
	 	<!-- 当前页面小于等于4 -->
	 	<li class="page-item" th:if="${(page.number + 1) le 4}" th:each="i : ${#numbers.sequence(2,5)}" 
			th:classappend="${(page.number + 1) eq i} ? 'active' : ''" >
			<a class="page-link tbpage-item" href="javascript:void(0);" th:attr="pageIndex=${i} - 1">
                <span th:text="${i}"></span>
            </a>
		</li>
 
		<li class="page-item disabled" th:if="${(page.number + 1) le 4}">
			<a href="javascript:void(0);" class="page-link tbpage-item">
				<span aria-hidden="true">...</span>
			</a>
		</li>
		
		<!-- 最后一页与当前页面之差，小于等于3 -->
		<li class="page-item disabled" th:if="${(page.totalPages-(page.number + 1)) le 3}">
			<a href="javascript:void(0);" class="page-link tbpage-item">
				<span aria-hidden="true">...</span>
			</a>
		</li>  
	 	<li class="page-item" th:if="${(page.totalPages-(page.number + 1)) le 3}" th:each="i : ${#numbers.sequence(page.totalPages-4, page.totalPages-1)}" 
			th:classappend="${(page.number + 1) eq i} ? 'active' : ''" >
			<a class="page-link tbpage-item" href="javascript:void(0);" th:attr="pageIndex=${i} - 1">
                <span th:text="${i}"></span>
           </a>
		</li>
	 
		 <!-- 最后一页与当前页面之差大于3，且  当前页面大于4-->
		 
		<li class="page-item disabled" th:if="${((page.number + 1) gt 4) && ((page.totalPages-(page.number + 1)) gt 3 )}">
			<a href="javascript:void(0);" class="page-link tbpage-item">
				<span aria-hidden="true">...</span>
			</a>
		</li> 
	 	<li class="page-item" th:if="${((page.number + 1) gt 4) && ((page.totalPages-(page.number + 1)) gt 3 )}" >
	 		<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number}">[[${page.number}]]</a>
	 	</li>
		<li class="page-item active" th:if="${((page.number + 1) gt 4) && ((page.totalPages-(page.number + 1)) gt 3 )}">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} + 1">[[${page.number + 1}]]</a>
		</li>
		<li class="page-item" th:if="${((page.number + 1) gt 4) && ((page.totalPages-(page.number + 1)) gt 3 )}">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} + 2">[[${page.number + 2}]]</a>
		</li>
		
		<li class="page-item disabled"  th:if="${((page.number + 1) gt 4) && ((page.totalPages-(page.number + 1)) gt 3 )}">
			<a href="javascript:void(0);" class="page-link tbpage-item">
				<span aria-hidden="true">...</span>
			</a>
		</li>
 
		<!-- 最后一页 -->
		<li class="page-item" th:classappend="${(page.number + 1) eq page.totalPages} ? 'active' : ''" >
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.totalPages} - 1">[[${page.totalPages}]]</a>
		</li>
 
 		<!-- 下一页 -->
 		<li class="page-item" th:classappend="*{last} ? 'disabled' : ''">
			<a href="javascript:void(0);" class="page-link tbpage-item" th:attr="pageIndex=${page.number} + 1" aria-label="Next">
				<span aria-hidden="true">»</span>
			</a>
		</li>
	</ul>
 
 
</div>

</body>
</html>